import { WxMiniGamePublish } from "./WxMiniGamePublish";
import { PublishBase } from "./PublishBase";
import { WebPublish } from "./WebPublish";
import { WxMiniGamePublish1 } from "./WxMiniGamePublish1";
import { WebPublish1 } from "./WebPublish1";
import { FaceBookPublish } from "./FaceBookPublish";
import { WebApkPublish } from "./WebApkPublish";
import { QQMiniGamePublish1 } from "./QQMiniGamePublish1";
import { QQMiniGamePublish } from "./QQMiniGamePublish";
import { VivoPublish } from "./VivoPublish";
import { OppoPublish } from "./OppoPublish";
import { BaiDuPublish } from "./BaiDuPublish";
import { TTPublish } from "./TTPublish";
import { HuaWeiPublish } from "./HuaWeiPublish";
import { BiliPublish } from "./BiliPublish";
import { EnumPublishType, EnumProjectType, IPublishVo, IProjectVo } from "../data/Config";
import { KuGouPublish } from "./KuGouPublish";
import { IosPublish } from "./IosPublish";
import { XiaoMiPublish } from "./XiaoMiPublish";
var publishHash = {};
publishHash[EnumProjectType.Laya2] = {
    [EnumPublishType.WxMiniGame]: WxMiniGamePublish,
    [EnumPublishType.Web]: WebPublish,
    [EnumPublishType.WebApk]: WebApkPublish,
    [EnumPublishType.QQ]: QQMiniGamePublish,
    [EnumPublishType.Vivo]: VivoPublish,
    [EnumPublishType.Oppo]: OppoPublish,
    [EnumPublishType.Baidu]: BaiDuPublish,
    [EnumPublishType.TouTiao]: TTPublish,
    [EnumPublishType.HuaWei]: HuaWeiPublish,
    [EnumPublishType.Bili]: BiliPublish,
    [EnumPublishType.KuGou]: KuGouPublish,
    [EnumPublishType.IOS]: IosPublish,
    [EnumPublishType.XiaoMi]: XiaoMiPublish,
}
publishHash[EnumProjectType.Laya1] = {
    [EnumPublishType.WxMiniGame]: WxMiniGamePublish1,
    [EnumPublishType.Web]: WebPublish1,
    [EnumPublishType.FaceBook]: FaceBookPublish,
    [EnumPublishType.QQ]: QQMiniGamePublish1
}

export function packGame(publishVo: IPublishVo, program: IProjectVo, version: string, checkRes: boolean, logFunc: (log: string) => void, complete: Function) {
    var publishCls = publishHash[program.type] && publishHash[program.type][publishVo.type];
    if (publishCls) {
        var publishItem: PublishBase = new publishCls();
        publishItem.init(publishVo, program);
        publishItem.packGame(version, checkRes, logFunc, complete);
    } else {
        logFunc && logFunc("该发布类型尚未支持");
        complete && complete(false);
    }
}


export function showPreView(publishVo: IPublishVo, program: IProjectVo, logFunc: (log: string) => void) {
    var publishCls = publishHash[program.type] && publishHash[program.type][publishVo.type];
    if (publishCls) {
        var publishItem: PublishBase = new publishCls();
        publishItem.init(publishVo, program);
        publishItem.showPreView(logFunc);
    } else {
        // logFunc && logFunc("该发布类型尚未支持");
        // complete && complete(false);
    }
}

export function createPublisher(publishVo: IPublishVo, program: IProjectVo) {
    var publishCls = publishHash[program.type] && publishHash[program.type][publishVo.type];
    if (publishCls) {
        var publishItem: PublishBase = new publishCls();
        publishItem.init(publishVo, program);
        return publishItem;
    }
    return null;
}